import { DressUpPage } from "../../uiScript/dressUp/DressUpPage";
import { DressUpTabListPage } from "../../uiScript/dressUp/DressUpTabListPage";
import { GameContextEventMgr } from "../GameContextEventMgr";
import { GameEventCenter } from "../GameEventCenter";
import { ItemLogicBase } from "../logicItem/ItemLogicBase";
import { FuncItemInfo, GlobalObj } from "../obj/GlobalObj";
import { PGCServer } from "../PGCServer";
import { SceneMgr } from "../SceneMgr";
import { GameTool } from "../tool/GameTool";
import ListDataRefresh_verse from "../tool/list/ListDataRefresh_verse";
import { GoodsType, LevelData } from "../uiComp/LevelListComp";
import { DressUpData, DressUpFilter } from "./data/DressUpData";
import { DressUpServerDataMgr, DressUpServerTag } from "./data/DressUpServerDataMgr";
import { DressUpTempMgr } from "./data/DressUpTempMgr";
import { DressUpDataParse } from "./DressUpDataParse";
import { DressUpItemLogic } from "./item/DressUpItemLogic";
import { MDressUp } from "./MDressUp";
import { MGoodsDescPage } from "./MGoodsDescPage";

export class DressUpList {

    private _view: DressUpPage;

    /** 装扮数据管理 */
    // private _dataMgrMap: Map<string, DressUpDataMgr> = new Map();

    /** 选中的装扮数据 */
    private _selectDatas: Map<string, DressUpData> = new Map();

    /** 选中层级功能按钮数据 */
    private _selectLevelData: LevelData<FuncItemInfo>;

    /** 右侧列表效果 */
    private _tabList: DressUpTabListPage;

    private _tempObj: any; // 公用变量

    private _canReselectList:boolean;

    /**
     * 初始化
     * @param view 装扮界面
     * @param filter 过滤数据
     */
    init(view: DressUpPage, filter?: DressUpFilter) {
        this._view = view;
        this._selectDatas.clear();
        this._view.clotheList.vScrollBarSkin = "";
        this._view.tempList.vScrollBarSkin = "";
        this._view.dressUpList.hScrollBarSkin = "pageres/bag/baise.png";
        this._view.dressDownList.hScrollBarSkin = "pageres/bag/baise.png";

        let upBar = this._view.dressUpList.scrollBar;
        let downBar = this._view.dressDownList.scrollBar;
        upBar.sizeGrid = "1,1,1,1,0";
        downBar.sizeGrid = "1,1,1,1,0";
        upBar.slider.bar.stateNum = 1;
        downBar.slider.bar.stateNum = 1;

        this._view.tempList.selectEnable = true;
        this._view.tempList.selectHandler = Laya.Handler.create(this, this.onClick, [this._view.tempList], false);;
        this._view.clotheList.selectEnable = true;
        this._view.clotheList.selectHandler = Laya.Handler.create(this, this.onClick, [this._view.clotheList], false);;
        this._view.dressUpList.selectEnable = true;
        this._view.dressUpList.selectHandler = Laya.Handler.create(this, this.onClick, [this._view.dressUpList], false);;
        this._view.dressDownList.selectEnable = true;
        this._view.dressDownList.selectHandler = Laya.Handler.create(this, this.onClick, [this._view.dressDownList], false);;

        this._view.dressDownList.renderHandler = Laya.Handler.create(this, this.onRenderDressDown, null, false);;
        this._view.dressUpList.renderHandler = Laya.Handler.create(this, this.onRenderDressUp, null, false);;
        this._view.clotheList.renderHandler = Laya.Handler.create(this, this.onRenderClothe, null, false);;
        this._view.tempList.renderHandler = Laya.Handler.create(this, this.onRenderTemp, null, false);;

        this._view.fun1Btn.on(Laya.Event.CLICK, this, this.onClickFunc, [this._view.fun1Btn]);
        this._view.fun2Btn.on(Laya.Event.CLICK, this, this.onClickFunc, [this._view.fun2Btn]);
        this._view.fun3Btn.on(Laya.Event.CLICK, this, this.onClickFunc, [this._view.fun3Btn]);

        GameEventCenter.Ins.on(GameEventCenter.TRANS_FINISHED, this, this.callbackRefreshList);
        GameEventCenter.Ins.on(GameEventCenter.REFRESH_DRESS_UP_TAB_LIST, this, this.refreshDressUpTabList);

        this._view.btn_nextStep.on(Laya.Event.CLICK, this, this.onClickFunc, [this._view.btn_nextStep]);


        this._initListComp(this._view.tempList);
        // this._initListComp(this._view.clotheList, 0, filter);
        // this._initListComp(this._view.dressUpList, 1, filter);
        // this._initListComp(this._view.dressDownList, 2, filter);
    }

    /** 打开右侧列表 */
    private _openDressTabList() {
        if (!this._tabList) {
            this._tabList = SceneMgr.createView(SceneMgr.DressUpTabListPage, []) as any;
            SceneMgr.scriptViewContainer.addChild(this._tabList);
            this._tabList.callback = MDressUp.Ins.clotheHandler;
        }
        this.refreshTabList();
        this._tabList.changeFaceItemSelectState(false);
        this._tabList.visible = true;
    }

    private refreshDressUpTabList() {
        if (!this._tabList) return;
        this._tabList.changeFaceItemSelectState(false);
        this.refreshTabList();
    }

    private refreshTabList() {
        let selectData = this.getSelectDressData();
        if (!this._selectLevelData || !selectData) return;
        let tempListData: any[];
        if (this._selectLevelData.type == GoodsType.ZUO_PIN) {

            tempListData = DressUpServerDataMgr.Ins.getTempTabListData(selectData);
            GameEventCenter.Ins.event(GameEventCenter.REFRESH_TAB_LIST, [tempListData]);
        } else if (this._selectLevelData.type == GoodsType.TAO_ZHUANG) {
            DressUpServerDataMgr.Ins.getListGoodsInSuitLuckyBox(selectData.define_id, Laya.Handler.create(this, (data: any) => {
                GameEventCenter.Ins.event(GameEventCenter.REFRESH_TAB_LIST, [data]);
            }));
        }
    }

    /** 关闭右侧列表 */
    private _closeDressTabList() {
        if (this._tabList) {
            this._tabList.visible = false;
        }
    }

    /** 初始化list数据刷新组件 */
    // private _initListComp(list: Laya.List, index: number, filter: DressUpFilter): void {
    // let comp: ListDataRefresh_verse = list.getComponent(ListDataRefresh_verse)
    // let dataMgr = this._dataMgrMap.get(list.name);
    // if (!dataMgr) {
    //     dataMgr = new DressUpDataMgr();
    //     this._dataMgrMap.set(list.name, dataMgr);
    // }
    // if (!comp) {
    //     comp = list.addComponent(ListDataRefresh_verse);
    //     comp.list = list;
    //     comp.dataHandler = dataMgr;
    // }
    // if (filter) {
    //     comp.isFilterData = true;
    //     comp.filterKey = filter.filterKey;
    //     comp.filterValue = filter.filterValue;
    // } else {

    //     comp.isFilterData = false;
    // }
    // comp.getTopPageData();
    // }

    private _initListComp(list: Laya.List, callback?: Laya.Handler): ListDataRefresh_verse {
        let comp: ListDataRefresh_verse = list.getComponent(ListDataRefresh_verse)
        if (!comp) {
            comp = list.addComponent(ListDataRefresh_verse);
            comp.list = list;
            let tempMgr = new DressUpTempMgr();
            comp.dataHandler = tempMgr;
        }
        comp.getTopPageData(callback);
        return comp;
    }

    refreshList(levelData: LevelData<FuncItemInfo>) {
        //TODO 切换list
        this._closeDressTabList();
        MGoodsDescPage.Ins.close();
        this._selectDatas.clear();
        this._selectLevelData = levelData;
        let lists = this.setListAdaptive(levelData);
        if (levelData.type == GoodsType.ZUO_PIN) {
            this._view.tempList.selectedIndex = -1;
            ItemLogicBase.resetSelectIdx(this._view.tempList);//重置自定义选中
            this._initListComp(this._view.tempList);
        } else {
            //this.dataReport(levelData.preNode.type, levelData.type);
            let ids = MDressUp.Ins.getSelectIdxArr(levelData);
            function getSelectIdx(arr:any[], id:number) {
                if(arr && id && GlobalObj.dressState != 1){// 交易状态不默认选中
                    for (let i = 0; i < arr.length; i++) {
                        const item = arr[i];
                        if(item.preform_id == id){
                            return i;
                        }
                    }
                }
                return -1;
            }
            // 切换数据
            DressUpServerDataMgr.Ins.getTabListArr(levelData, lists.length >= 2, Laya.Handler.create(this, (levelData: LevelData<FuncItemInfo>, arr: any[]) => {
                DressUpDataParse.loadArrJson(arr[0], Laya.Handler.create(this, ()=>{
                    DressUpDataParse.loadArrJson(arr[1], Laya.Handler.create(this, ()=>{
                        // 是眼影并且有选中数据，就在onClick里面处理了downList数据了
                        this._canReselectList = true;
                        lists.forEach((list: Laya.List, idx: number) => {
                            let listSelectIdx:number = -1;
                            if(!this._canReselectList && idx == 1){
                                listSelectIdx = getSelectIdx(list.array, ids[idx]);
                            }else{
                                listSelectIdx = getSelectIdx(arr[idx], ids[idx]);
                                if(this._canReselectList)
                                    this._canReselectList = !(listSelectIdx != -1 && idx == 0 && levelData.preNode.type == GoodsType.Z_YAN_YING);
                                list.array = arr[idx];
                            }
                            ItemLogicBase.resetSelectIdx(list);//重置自定义选中
                            list.selectedIndex = -1;
                            list.selectedIndex = listSelectIdx; // 重置list选中
                            listSelectIdx >= 0 && list.scrollTo(listSelectIdx); // 重置list位置
                        });
                        this._canReselectList = true;
                    }))
                }))
            }, [levelData]));
        }
        // 刷新ui
        this.refreshFuncBtn();
    }



   


    private refreshTabListDatas() {
        let levelData = this._selectLevelData;
        // 切换数据
        if (levelData.type == GoodsType.ZUO_PIN) {
            this._initListComp(this._view.tempList, Laya.Handler.create(this, this.refreshTabList));
        }
    }

    setListAdaptive(levelData: LevelData<FuncItemInfo>) {
        let list: Laya.List[];
        let parentType = levelData.preNode.type;
        let levelType = levelData.type;

        let parentSingleTypes = [ // 父类型就可以确定 单个list
            GoodsType.WU_GUAN,
            GoodsType.FU_SHI,
            GoodsType.Z_FEN_DI_YE,
        ];

        let singleTypes = [  // 类型就可以确定 单个list
            GoodsType.Z_FEN_DI_YE,
            GoodsType.TAO_ZHUANG,
            GoodsType.Z_XIU_RONG,
            GoodsType.Z_JIE_MAO,
            GoodsType.Z_MEI_MAO,
        ];
        let doubleTypes = [ // 类型就可以确定 多个list
            GoodsType.Z_DING_ZHUANG,
            GoodsType.Z_KOU_HONG,
            GoodsType.Z_SAI_HONG,
            GoodsType.Z_YAN_XIAN,
            GoodsType.Z_YAN_YING,
        ];
        if (levelType == GoodsType.Z_JIE_MAO && parentType == GoodsType.WU_GUAN) {// 是妆容的睫毛
            let delIdx = doubleTypes.indexOf(levelType)
            doubleTypes.splice(delIdx, 1);
        }
        if (parentSingleTypes.indexOf(parentType) >= 0 ||
            singleTypes.indexOf(levelType) >= 0) {// clothelist 作为五官数据存放的list
            if (parentType == GoodsType.FU_SHI || levelType == GoodsType.TAO_ZHUANG) { // 服饰
                list = [this._view.clotheList];
            } else { // 妆容
                list = [this._view.clotheList];
            }
        }
        if (doubleTypes.indexOf(levelType) >= 0 || doubleTypes.indexOf(parentType) >= 0) {// 多个list显示  妆容
            list = [this._view.dressUpList, this._view.dressDownList];
        }

        if (levelData.type == GoodsType.ZUO_PIN) {
            list = [this._view.tempList];
        }

        let hasTopList = this._view.funcBox04List.visible;
        // 位置计算
        if (hasTopList) { // 是否有顶部list 有则显示的下移
            list[0].top = 102;
        } else {

            list[0].top = 42;
        }
        if (list.length > 1) { // 两个list 是否有滑动条和是否有多余数据有关
            list[0].bottom = this._view.contentBox.height - (list[0].top + 193);
            list[1].bottom = hasTopList ? 10 : 68;
            list[0].repeatX = 3;
            list[0].repeatY = 1;
        } else {
            if (list[0].name == "clotheList" || list[0].name == "dressUpList" || list[0].name == "tempList") {
                list[0].height = hasTopList ? 385 : 454;
            }
            list[0].repeatX = 3;
            list[0].repeatY = 3;
            list[0].bottom = NaN;
        }
        this.setListVisible(list);
        return list;
    }

    private setListVisible(showLists: Laya.List[]): void {
        let allList = [this._view.tempList, this._view.clotheList, this._view.dressDownList, this._view.dressUpList];
        let idx: number;
        for (let index = 0; index < allList.length; index++) {
            const list = allList[index];
            if (list) {
                idx = showLists.indexOf(list);
                list.visible = idx >= 0;
                list.array = [];
            }
        }
    }

    refreshFuncBtn() {
        this._view.btn_nextStep.visible = GlobalObj.dressState == 2;

        //处理按钮显示
        if (GlobalObj.dressState >= 1) {
            this._view.fun1Btn.visible =
                this._view.fun2Btn.visible =
                this._view.fun3Btn.visible = false;
        } else {
            let targetData = this.getSelectDressData();

            this._view.fun1Btn.visible =
                this._view.fun2Btn.visible =
                this._view.fun3Btn.visible = true;

            // 切换功能按钮
            let labTexts: DressUpFuncBtnType[];
            let tempType = [GoodsType.FU_SHI, GoodsType.WU_GUAN];
            if (this._selectLevelData
                && (tempType.indexOf(this._selectLevelData.type) >= 0 // 是否只显示保存模板
                    || tempType.indexOf(this._selectLevelData.preNode.type) >= 0)) { // 是否只显示保存模板

                labTexts = [null, null, DressUpFuncBtnType.SAVE_TEMP];

            } else {

                if (GlobalObj.getGoodsNum(targetData)) {//TODO
                    labTexts = [DressUpFuncBtnType.SELL, DressUpFuncBtnType.CHANGE, DressUpFuncBtnType.SAVE_TEMP];
                } else {
                    if (!targetData) {
                        labTexts = [null, null, DressUpFuncBtnType.SAVE_TEMP];
                    } else {
                        labTexts = [DressUpFuncBtnType.SHOP];
                    }
                }
                switch (this._selectLevelData.type) {
                    case GoodsType.TAO_ZHUANG:
                        if (GlobalObj.isFa()) {

                            labTexts = [null, null, DressUpFuncBtnType.LOTTERY];
                        } else {

                            labTexts = [null, null];
                        }
                        break;
                    case GoodsType.ZUO_PIN:
                        if (GlobalObj.isSaveTemp) {
                            labTexts = [DressUpFuncBtnType.REPLACE_TEMP, DressUpFuncBtnType.NEW_TEMP];
                        } else { // 不显示按钮，直接切换作品
                            labTexts = [null, null];
                        }
                        break;

                    default:
                        break;
                }

            }

            this._setDefaultBtnLab(labTexts);
        }
    }

    private _setDefaultBtnLab(texts: DressUpFuncBtnType[]) {
        // 刷新按钮状态
        let lab1 = this._view.fun1Btn.getChildAt(0) as Laya.Label;
        let lab2 = this._view.fun2Btn.getChildAt(0) as Laya.Label;
        let lab3 = this._view.fun3Btn.getChildAt(0) as Laya.Label;
        this._setBtnLab(texts, [lab1, lab2, lab3], [this._view.fun1Btn, this._view.fun2Btn, this._view.fun3Btn])
    }

    private _setBtnLab(texts: DressUpFuncBtnType[], labs: Laya.Label[], btns: Laya.Image[]) {
        let startPos = 244;
        let space = 12;
        for (let index = 0; index < btns.length; index++) {
            const btn = btns[index];
            const lab = labs[index];
            const text = texts[index];
            if (text) {
                lab.text = text;
                btn.visible = true;
                btn.x = startPos;
                startPos += (btn.width + space);
            } else {
                btn.visible = false;
            }
        }
    }

    /** 点击功能按钮 */
    onClickFunc(btn: Laya.Button) {
        let lab = btn.getChildAt(0) as Laya.Label;
        console.log("点击的按钮:" + lab.text);
        let targetData = this.getSelectDressData();
        switch (lab.text) {
            case DressUpFuncBtnType.SELL:
                MDressUp.Ins.onSell(targetData, Laya.Handler.create(this, this.callbackRefreshList));
                break;
            case DressUpFuncBtnType.CHANGE:
                MDressUp.Ins.onChange(targetData);
                break;
            case DressUpFuncBtnType.SAVE_TEMP:
                DressUpServerDataMgr.Ins.existTemp(Laya.Handler.create(this, (exist: boolean) => {
                    MDressUp.Ins.onSaveTemplete(targetData);
                    if (!exist) {
                        Laya.timer.frameOnce(1, this, () => {
                            MDressUp.Ins.onNewTemplete(Laya.Handler.create(this, this.refreshTabListDatas));
                        })
                    }
                }));
                break;
            case DressUpFuncBtnType.REPLACE_TEMP:
                MDressUp.Ins.onReplaceTemplete(targetData, Laya.Handler.create(this, this.refreshTabListDatas));
                break;
            case DressUpFuncBtnType.NEW_TEMP:
                MDressUp.Ins.onNewTemplete(Laya.Handler.create(this, this.refreshTabListDatas));
                break;
            case DressUpFuncBtnType.SHOP:
                MDressUp.Ins.onClickBuy(targetData, Laya.Handler.create(this, this.callbackRefreshList));
                break;
            case DressUpFuncBtnType.LOTTERY:
                MDressUp.Ins.onLottery(targetData);
                break;
            case DressUpFuncBtnType.NEXT_STEP:
                MDressUp.Ins.onClickNextStep(targetData);
                break;
            default:
                break;
        }
    }

    /** 用于回调刷新妆容列表 */
    private callbackRefreshList() {
        // 刷新当前选中levelData
        this.refreshList(this._selectLevelData);
    }

    public getSelectDressData() {
        return this._selectDatas.get(this._view.clotheList.name)
            || this._selectDatas.get(this._view.tempList.name)
            || this._selectDatas.get(this._view.dressUpList.name);
    }

    public delSelectDressData(value: DressUpData) {
        let self = this;
        self._tempObj = undefined;
        this._selectDatas.forEach((item: DressUpData, key: string) => {
            if (item && value && item.preform_id == value.preform_id) {
                self._tempObj = key;
            }
        });
        if (self._tempObj) {
            this._selectDatas.delete(self._tempObj);
        }
    }


    /** 点击了部位数据 */
    onClick(list: Laya.List, index: number) {

        if (list && !list.destroyed) {
            let type = this._selectLevelData.type;
            let pretype = this._selectLevelData.preNode.type;
            let dressUpData: DressUpData = list.getItem(index);
            ItemLogicBase.selectItem(list);
            if (!dressUpData) return;
            let curSelectData = this.getSelectDressData();

            if (dressUpData && dressUpData.preform_id == -1) {
                console.log("清理妆容");
                MGoodsDescPage.Ins.close();
                let downList = this._view.dressDownList;
                downList.selectedIndex = -1;
                this._selectDatas.delete(downList.name);
                this._selectDatas.delete(this._view.dressUpList.name);

                MDressUp.Ins.clearTabDressUp(this._selectDatas, this._selectLevelData);
                this._setDefaultBtnLab([null, null, DressUpFuncBtnType.SAVE_TEMP]);
                return;
            } else {
                this._selectDatas.set(list.name, dressUpData);

                let dressUpList = this._view.dressUpList;
                let isChange = false;

                let dressDownList = this._view.dressDownList;

                curSelectData = this.getSelectDressData();
                let isYanying = pretype == GoodsType.Z_YAN_YING;

                if (isYanying && list.name == "dressUpList") { // 眼影特殊处理画法
                    let yanyingDatas = DressUpServerDataMgr.Ins.getYanyingDatas(curSelectData, this.SelectLevelData);
                    if (dressDownList.array != yanyingDatas || dressDownList.selectedIndex < 0) {
                        // 需要切换
                        dressDownList.array = yanyingDatas;
                        dressDownList.selectedIndex = -1;
                        if(this._canReselectList)
                            dressDownList.selectedIndex = 0;
                        isChange = true;
                    }
                } 
                if (isYanying && list.name == "dressDownList") { // 眼影特殊处理画法

                    let yanyingDatas = DressUpServerDataMgr.Ins.getYanyingDataByType(1, type);
                    let isDoubleColor = dressDownList.array == yanyingDatas; //多色
                    let colorLen = curSelectData && curSelectData.color && curSelectData.color.length;
                    if (!curSelectData || !curSelectData.color || (colorLen <= 1 && isDoubleColor) || (colorLen > 1 && !isDoubleColor)) {

                        let yanyingId = this._findYanYingSelectIdx(dressUpList, isDoubleColor); //找到对应单色或者多色的数据 返回对应的index
                        if (yanyingId == -1) {
                            console.warn("没找到对应的眼影:" + isDoubleColor);
                        }
                        dressUpList.selectedIndex = -1;
                        dressUpList.selectedIndex = yanyingId;
                        dressUpList.scrollTo(yanyingId);
                        isChange = true;
                    }

                } 
                
                if(!isYanying){
                    if (dressDownList.visible && dressDownList.selectedIndex < 0) {
                        dressDownList.selectedIndex = 0;
                        isChange = true;
                    }
                    if (dressUpList.visible && dressUpList.selectedIndex < 1 && dressUpList.array.length > 1) {
                        dressUpList.selectedIndex = 1;
                        isChange = true;
                    }
                }

                // 点击数据
                if (list.name != "dressDownList")// 下方的数据不是用于妆容和服饰的
                {
                    if (curSelectData) {

                        if ([GoodsType.TAO_ZHUANG, GoodsType.ZUO_PIN].indexOf(type) >= 0) {
                            this._openDressTabList();
                        } else {
                            if (GlobalObj.dressState < 1
                                && [GoodsType.WU_GUAN, GoodsType.FU_SHI].indexOf(pretype) == -1
                                && [GoodsType.Z_YAN_XIAN, GoodsType.Z_JIE_MAO, GoodsType.Z_MEI_MAO].indexOf(type) == -1) {
                                MDressUp.Ins.openGoodsDesc(curSelectData);
                            }
                        }
                    }
                }
                if (isChange) { // 触发切换了会再次执行onClick逻辑 就不再往下重复执行了
                    return;
                }
            }
            MDressUp.Ins.onClickListItem(curSelectData, dressUpData, this.SelectLevelData);

            if (GlobalObj.dressState !== 1) { // 交易状态不换妆容
                if ((GlobalObj.dressState == 2 && !DressUpServerDataMgr.Ins.canUse(curSelectData, this.SelectLevelData, dressUpData))) {

                } else {
                    MDressUp.Ins.onClickDressUpItem(this._selectLevelData, this._selectDatas, curSelectData);
                }
            }

            // 刷新按钮状态
            this.refreshFuncBtn();
        }
    }

    private _findYanYingSelectIdx(list: Laya.List, isDoubleColor: boolean) {
        let yanyingDatas = list.array;
        for (let index = 0; index < yanyingDatas.length; index++) {
            const item = yanyingDatas[index];
            if (item.preform_id == -1 || !item.color) {
                continue;
            }
            if (item.color.length > 1 && isDoubleColor) {
                return index;
            }
            if (item.color.length == 1 && !isDoubleColor) {
                return index;
            }
        }
        return -1;
    }


    onRenderDressDown(box: Laya.Box, index: number) {
        ItemLogicBase.createLogic(box, [box.dataSource, false, false, true], DressUpItemLogic, this._view.dressDownList, index);
    }

    onRenderDressUp(box: Laya.Box, index: number) {
        let needShowPrice: boolean = [this._selectLevelData.type, this._selectLevelData.preNode.type, this._selectLevelData.preNode.preNode.type].indexOf(GoodsType.ZHUANG_RONG) >= 0;
        let isWuGuan = this._selectLevelData.preNode.type == GoodsType.WU_GUAN;
        ItemLogicBase.createLogic(box, [box.dataSource, needShowPrice, false, isWuGuan], DressUpItemLogic, this._view.dressUpList, index);
    }

    onRenderClothe(box: Laya.Box, index: number) {
        let needShowPrice: boolean = [this._selectLevelData.type, this._selectLevelData.preNode.type, this._selectLevelData.preNode.preNode.type].indexOf(GoodsType.ZHUANG_RONG) >= 0;
        let isWuGuan = this._selectLevelData.preNode.type == GoodsType.WU_GUAN;

        ItemLogicBase.createLogic(box, [box.dataSource, needShowPrice, true, isWuGuan], DressUpItemLogic, this._view.clotheList, index);
    }
    onRenderTemp(box: Laya.Box, index: number) {

        ItemLogicBase.createLogic(box, [box.dataSource], DressUpItemLogic, this._view.tempList, index);
    }

    public get SelectLevelData() {
        return this._selectLevelData;
    }

    private _clearRenderHandler(list: Laya.List) {
        if (list) {

            let rendHandler = list.renderHandler;
            list.renderHandler = null;
            rendHandler && rendHandler.recover();
        }
    }

    destroy() {
        this._selectDatas.clear();
        this._view.fun1Btn.off(Laya.Event.CLICK, this, this.onClickFunc);
        this._view.fun2Btn.off(Laya.Event.CLICK, this, this.onClickFunc);
        this._view.fun3Btn.off(Laya.Event.CLICK, this, this.onClickFunc);
        GameEventCenter.Ins.off(GameEventCenter.REFRESH_DRESS_UP_TAB_LIST, this, this.refreshDressUpTabList);
        GameEventCenter.Ins.off(GameEventCenter.TRANS_FINISHED, this, this.callbackRefreshList);
        this._clearRenderHandler(this._view.dressUpList);
        this._clearRenderHandler(this._view.clotheList);
        this._clearRenderHandler(this._view.tempList);
        this._clearRenderHandler(this._view.dressDownList);

        this._view = null;
        DressUpServerDataMgr.Ins.clear();
        SceneMgr.closeView(this._tabList);
        this._tabList = null;
    }
}

enum DressUpFuncBtnType {
    SELL = "出售",
    CHANGE = "交换",
    SAVE_TEMP = "保存造型模版",
    SHOP = "购买",
    LOTTERY = "前往抽奖",
    REPLACE_TEMP = "替换",
    NEW_TEMP = "新建",
    NEXT_STEP = "下一步",
}